package com.blog.controller;

import com.alibaba.fastjson.JSONObject;
import com.blog.pojo.Blog;
import com.blog.service.ArchiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * Copyright (C), 2022
 * Author: 苏大大
 * Date: 2022-06-06 9:25
 * FileName: ArchivesController
 * Description: 归档控制层
 */
@RestController
@RequestMapping("archives")
@Slf4j
public class ArchivesController {

    @Resource
    private ArchiveService archiveService;

    @GetMapping("/getArchivesList")
    public String getArchivesList(){
        JSONObject object=new JSONObject();
        List<Blog> blogList=archiveService.getArchivesList();
        object.put("ArchivesList",blogList);
        if(blogList==null){
            object.put("message","获取归档内容失败!");
        }
        object.put("flag",blogList!=null);
        object.put("total",blogList.size());
        return object.toJSONString();
    }
}
